<template>
	<view class="inventoryEdit">
		<uni-list>
			<uni-list-item title="商品名称" :rightText="detail.commodityName"></uni-list-item>
			<uni-list-item title="仓库名称" :rightText="detail.warehouseName"></uni-list-item>
			<uni-list-item title="仓库编码" :rightText="detail.warehouseCode"></uni-list-item>
			<uni-list-item title="规格" :rightText="detail.commoditySpecification"></uni-list-item>
			<uni-list-item title="盒箱条形码" :rightText="detail.commodityVaseCode"></uni-list-item>
			<uni-list-item title="外箱条形码" :rightText="detail.commodityCaseCode"></uni-list-item>
			<uni-list-item title="操作类型">
				<template slot="footer">
					<view class="toRight">
						<uni-data-checkbox v-model="type" :localdata="range"></uni-data-checkbox>
					</view>
				</template>
			</uni-list-item>
			<uni-list-item title="数量">
				<template slot="footer">
					<view class="toRight">
						<uni-number-box v-model="count" min="1"></uni-number-box>
					</view>
				</template>
			</uni-list-item>
			<uni-list-item title="备注">
				<template slot="footer">
					<view class="toRight">
						<uni-easyinput type="text" v-model="remarks" placeholder="请输入备注(选填)" :inputBorder="false" />
					</view>
				</template>
			</uni-list-item>
		</uni-list>
		<!-- 按钮 -->
		<view class="buttonWrap">
			<button type="primary" size="mini" @click="handleSubmit">提 交</button>
			<button size="mini" @click="handleCancel">取 消</button>
		</view>
	</view>
</template>

<script>
	export default {
		name: "inventoryEdit",
		data() {
			return {
				type: "import",
				range: [{
					"value": "import",
					"text": "入库"
				}, {
					"value": "export",
					"text": "出库"
				}],
				count: 1,
				remarks: "",
				detail: {}
			}
		},
		onLoad(options) {
			this.detail = JSON.parse(options.detail)
		},
		methods: {
			handleSubmit() {
				uni.showModal({
					title: "提示",
					content: "确认修改吗？",
					success: async (res) => {
						if (res.confirm) {
							try {
								await this.request("editInventory", {
									shopId: this.detail.commodityId,
									handle: this.type,
									count: this.count,
									remarks: this.remarks,
								})

								uni.showToast({
									title: "操作成功",
									success() {
										uni.navigateBack()
									}
								})
							} catch (e) {
								uni.showToast({
									title: "操作失败",
									icon: "error"
								})
							}
						}
					}
				})
			},
			handleCancel() {
				uni.navigateBack()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.inventoryEdit {
		padding: 15rpx 20rpx;
	}
</style>
